import { join } from 'path'

export default {
	port: '3000',
	staticPath: '../public',
	jwtKey: "asdg364355#$%^&%$#!@",
	aliyunOssConfig: {
		accessKeyId: 'LTAIXlLtUBP2Cr8F',
		accessKeySecret: 'B6i0KohY3yf0YGM6xsdqrXeGgFMifs',
	},
	routePrefix: {
		app: '/app',
		admin: '/admin',
		apiPrefix: {
		  app: {
			user: "/user",
			article: "/article",
			link: "/link"
		  },
		  admin: {
			menu: "/menu",
			lib: "/lib"
		  }
		}
	  },
	  setPrefix: function(path: string): string {
		let pathArr: string[] = path.split("/");
		// @ts-ignore
		return `${this.routePrefix[pathArr[0]]}${this.routePrefix.apiPrefix[pathArr[0]][pathArr[1]]}`
	},
	orm: null,
	mysql: {
		type: "mysql",
		host: "localhost",
		port: 3306,
		username: "root",
		password: "root",
		database: "myblog",
		synchronize: false,
		logging: true,
		entities: [ join(__dirname, "../entity/**/*{.js,.ts}") ],
	},
	cors: {
		Origin: '*',
		Headers: 'token',
		configCors: function () {
			return {
				"Access-Control-Allow-Origin": this.Origin,
				"Access-Control-Allow-Headers": this.Headers
			}
		}
	},
	logConfig: {
		appenders: {
			//系统日志
			access: {
				type: 'dateFile',
				pattern: '_yyyy-MM-dd.log',
				alwaysIncludePattern: true,
				encoding: "utf-8",
				category: "access",
				filename: join(__dirname, '../../logs/access')
			},
			// 应用日志
			application: {
				type: 'dateFile',
				pattern: '_yyyy-MM-dd.log',
				alwaysIncludePattern: true,
				encoding: "utf-8",
				category: "application",
				filename: join(__dirname, '../../logs/application')
			},
			out: {
				type: 'console'
			}
		},
		categories: {
			default: { appenders: ['out'], level: 'info' },
			access: { appenders: ['access'], level: 'info' },
			application: { appenders: ['application'], level: 'WARN' }
		}
	},
}